<?php
Yii::import('ext.yii-easyui.base.EuiController');
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends EuiController//CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();

	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();

    public function beforeRender($action){

            Counter::runCounter();
        return parent::beforeAction($action);        
    }

	/*public function beforeAction($action){
        $actionName=$this->action->id;
        $controllerName=$this->uniqueid;
        $sum=0;
        $counter=array();
        $counter=Yii::app()->session['counter'];
        $test=Yii::app()->session['test'];

        if($counter!=null){
            if($actionName=='create'){//&&$counter['flag']){
                //$counter['flag']=false;//true,false
                //throw new Exception("Error Processing Request -1".$actionName);
                $counter['flag']=$counter['flag']!=true? true:false;
                
            }if($actionName!='çreate'){//&&$counter['flag']){
                //$counter['flag']=false;
                //throw new Exception("Error Processing Request -1".$actionName);
                $counter['flag']=$counter['flag']!=true? false:true;
                //throw new Exception("Error Processing Request".$counter['flag']);
            }else{
                $counter['flag']=$counter['flag']!=true? true:false;
                //$counter['flag']=true;
            }

        
        	if($actionName=='create' && !$counter['flag']){
                
                CounterBralink::model()->updateCounters(array( 'sum' => 1),
                                  'type="'.$controllerName.'"'
                          );
                
                $sum=CounterBralink::model()->find('type=:type',array(':type'=>$controllerName))->sum;
                //$counter['flag']=false;
                Yii::app()->session['dont']=true;
        	}
            else if($actionName!='create' && !$counter['flag']){

                $test.=$actionName;

                
                CounterBralink::model()->updateCounters(array( 'sum' => -1),
                                  'type="'.$controllerName.'"'
                          );
                
                $counter['flag']=true;
            }
        }
        Yii::app()->session['counter']=array('flag'=>$counter['flag'],'userLogin'=>$sum);
        Yii::app()->session['test']=$test;
        var_dump(Yii::app()->session['test']);

    	return parent::beforeAction($action);
    }*/
}